﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ERPForms
{
    public partial class LocalitatiFrm : FrmRezumat
    {

        private Int32 _codJudet = 0;
        public Int32 CodJudet
        {
            get { return _codJudet; }
            set { _codJudet = value; }
        }
        private String _adLocalitate = String.Empty;
        public String LocalitateAdaugate
        {
            set { _adLocalitate = value.ToUpper(); }
        }


        public LocalitatiFrm(ModuleClass mInfo)
            : base(mInfo)
        {
            InitializeComponent();
        }

        private void LoadLoc(object sender, EventArgs e)
        {
            
            SqlConnection con = DeschideConexiune(workConnString);
            
            this.localitatiTableAdapter.Connection = con;
            this.localitatiTableAdapter.Fill(this.eSRPDataSet.Localitati);
            if (_codJudet != 0)
            {
                this.localitatiTableAdapter.FillByJudet(this.eSRPDataSet.Localitati, _codJudet);
                iDJudetColumn.Visible = false;
                eSRPDataSet.Localitati.IDJudetColumn.DefaultValue = CodJudet;
                
            }
            else
                this.localitatiTableAdapter.Fill(this.eSRPDataSet.Localitati);

            this.judeteTableAdapter.Connection = con;
            this.judeteTableAdapter.Fill(this.eSRPDataSet.Judete);
            InchideConexiune(con);
            AddButton("Salveaza", global::ERPStudio.Properties.Resources.salvare, Salvare, ToolStripItemAlignment.Right, true);
            this.listBndSourceMain.Add(localitatiBindingSource);
            listTableAdaptor.Add(this.localitatiTableAdapter.Adapter);
            
            if (_adLocalitate!=String.Empty)
            {
                localitatiDGV.AllowUserToAddRows = false;
                Adauga(this, null);
                localitatiBindingSource.MoveLast();
                ESRPDataSet.LocalitatiRow dr = ((DataRowView)localitatiBindingSource.Current).Row as ESRPDataSet.LocalitatiRow;
                dr.Nume = _adLocalitate;
            }
            HandleSalvare += Salvare;

        }

        private void localitatiDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
                return;
            DataGridView dgv = sender as DataGridView;
            if (e.ColumnIndex == numeColumn.Index)
            {
                dgv[e.ColumnIndex, e.RowIndex].Value = dgv[e.ColumnIndex, e.RowIndex].Value.ToString().ToUpper();
            }
        }
    }
}
